#include "EdgeShifter.h"


EdgeShifter::EdgeShifter()
{
	watcher = EdgeWatcher();
	sampleChoice = 0; //sample low.
	shifter = Shifter();
}

EdgeShifter::EdgeShifter(BitPointer& pointerToWatch, 
			 BitPointer& shiftPointer,
			unsigned char shiftTrigger,
			unsigned int size, bool dir, bool i)
{
	watcher = EdgeWatcher(pointerToWatch, 1);
	sampleChoice = shiftTrigger;
	shifter = Shifter(size, shiftPointer, dir, i);
}

BitArray EdgeShifter::get()
{
	return shifter.get();
}

void EdgeShifter::set(BitArray& array)
{
	shifter.set(array);
}

bool EdgeShifter::finished()
{
	return shifter.getFinished();
}

void EdgeShifter::run()
{
	//run the watcher
	watcher.run();
	switch(sampleChoice)
	{
		case EdgeWatcher::LowEdge : //low
			if(watcher.low()==1)
				shifter.shift();
			break;
		case  EdgeWatcher::HighEdge : //high
			if(watcher.high()==1)
				shifter.shift();
			break;
		case  EdgeWatcher::RisingEdge : //rising
			if(watcher.rising()==1)
				shifter.shift();
			break;
		case EdgeWatcher::FallingEdge : //falling
			if(watcher.falling()==1)
				shifter.shift();
			break;
		default : //low
			if(watcher.low()==1)
				shifter.shift();
			break;
	}
}


